home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / Examples / PacMan / PacManGameBrain.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  103 lines

  1.  
  2. #import <gamekit/gamekit.h>
  3. #import "PacManGameBrain.h"
  4. #import "PacManView.h"
  5. #import "Player.h"
  6. #import "PacManPreferencesBrain.h"
  7. #import "FruitView.h"
  8. #import <stdio.h>
  9. #import <string.h>
  10.  
  11. // fruit values
  12. static long fruitval[NUMFRUITVALS] = { 100, 200, 300, 300, 500, 700,
  13.     700, 1000, 1000, 2000, 2000, 3000, 3000, 3000, 3000, 5000 };
  14.  
  15. @implementation PacManGameBrain
  16.  
  17. - nextLevel        // we add fruit basket's display of the level to this
  18. {
  19.     [super nextLevel];
  20.     [fruitBasket showLevel:level];
  21.     return self;
  22. }
  23.  
  24. - makeGameInfo
  25. {    // This could be replaced by using the GameInfo palette.  I'm not using
  26.     // the palette yet since the GameInfo object may change, and then trying
  27.     // to load the .nib might crash until I add versioning in the read and
  28.     // write methods...
  29.     id info = [super makeGameInfo];
  30.  
  31.     // Set up for the sound in our game; 2 types with 3 sounds each.
  32.     // 2 streams is enough to overlap the sounds a little without them
  33.     // getting too delayed.
  34.     [[[info setnumSoundTypes:1] setnumSoundStreams:3] setnumSounds:6];
  35.  
  36.     // Giving three pacs to begin with.
  37.     [info setNumOneUps:3];
  38.  
  39.     // highscores:  only five per user on the network server:
  40.     [info setMaxScoresPerPlayerTable:0 net:YES to:5];
  41.     return info;
  42. }
  43.  
  44. - appDidInit:sender        // after init, but before 1st event.
  45. {    // Allocate the bonus trackers and a frame for the PlayerUpView
  46.     id xtraManTracker = [[BonusTracker alloc] init];
  47.     id ghostTracker = [[BonusTracker alloc] init];
  48.     id fruitTracker = [[ArrayBonusTracker alloc]
  49.             initForBonuses:fruitval count:NUMFRUITVALS];
  50.     NXRect pacFrame = {{PAC_WIDTH * 2, PAC_WIDTH}, {PAC_WIDTH, PAC_WIDTH}};
  51.     
  52.     [super appDidInit:sender];
  53.     
  54.     // set up bonus trackers for eating ghosts and getting extra men
  55.     [xtraManTracker setBaseValue:10000];    // first xtra man at 10,000 pts.
  56.     [(BonusTracker *)xtraManTracker setIncrement:15000];
  57.                                         // next xtra every 15,000 pts...
  58.     [ghostTracker setBaseValue:200];    // first ghost is worth 200 pts.
  59.     [ghostTracker setMultiplier:2];        // each ghost is worth 2x previous
  60.     [gameScreen setGhostTracker:[scoreKeeper addBonusTracker:ghostTracker]];
  61.     [gameScreen setFruitTracker:[scoreKeeper addBonusTracker:fruitTracker]];
  62.  
  63.     // configure the PlayerUpView
  64.     [oneUpView setImage:[NXImage findImageNamed:"Pacs.tiff"]];
  65.     [oneUpView setImageFrame:&pacFrame];
  66.     [oneUpView setMargin:8.0];
  67.     [oneUpView setExtraManBonusTracker:xtraManTracker];
  68.     
  69.     // Set up the FruitBasket window to autosave it's location.
  70.     [[fruitBasket window] setFrameUsingName:"FruitBasket"];
  71.     [[fruitBasket window] setFrameAutosaveName:"FruitBasket"];
  72.     [fruitBasket showLevel:1];
  73.     
  74.     return self;
  75. }
  76.  
  77. - layerWindows
  78. {
  79.     // make sure the windows are layered properly
  80.     // Fruit Basket is to be on the bottom, so order it front first.
  81.     if (![[fruitBasket window] delegate] ||
  82.             [[[fruitBasket window] delegate] windowUp])
  83.         [[fruitBasket window] orderFront:self];
  84.     return [super layerWindows];
  85. }
  86.  
  87. - windowDidMove:sender        // move fruit basket and status with game window 
  88. {    // we completely override super's method, since the window goes to
  89.     // a totally different spot... (lower left rather than upper left, and
  90.     // we have to move two windows instead of just one.)
  91.     NXRect gameFrame;
  92.     
  93.     [gameWindow getFrame:&gameFrame];
  94.     [[fruitBasket window] moveTo:(NX_X(&gameFrame) - 137)
  95.         :(NX_Y(&gameFrame) - 53)];
  96.     [[levelText window] moveTo:(NX_X(&gameFrame) - 137)
  97.         :NX_Y(&gameFrame)];
  98.     return self;
  99. }
  100.  
  101.  
  102. @end
  103.